package com.kaluli.system.security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.util.StringUtils;

public class SimpleRememberMeService implements RememberMeServices {

	private final static String USER_HEADER = "user";
	private final static String PASS_HEADER = "pass";

	@Override
	public Authentication autoLogin(HttpServletRequest request,
			HttpServletResponse response) {

		String user = request.getHeader(USER_HEADER);
		String pass = request.getHeader(PASS_HEADER);
		
		if(StringUtils.isEmpty(user) && StringUtils.isEmpty(pass) ) {
			user = request.getParameter(USER_HEADER);
			pass = request.getParameter(PASS_HEADER);
		}
		SimpleUsernamePasswordAuthenticationToken token = new SimpleUsernamePasswordAuthenticationToken(
				user, pass);	
		return token;
	}

	@Override
	public void loginFail(HttpServletRequest request,
			HttpServletResponse response) {
	}

	@Override
	public void loginSuccess(HttpServletRequest request,
			HttpServletResponse response,
			Authentication successfulAuthentication) {
	}

}
